package com.hyk.commonLib.common.utils.netRequest;


import com.trello.rxlifecycle4.LifecycleTransformer;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableTransformer;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * Created by 贺玉琨 on 2019/7/6.
 */
public interface INetUtils {

    <T> T getServerInstance(Class<T> server);

    default <T> ObservableTransformer<T, T> getCompose() {
        return getCompose(null);
    }

    default <T> ObservableTransformer<T, T> getCompose(LifecycleTransformer<T> transformer) {
        return upstream -> {
            Observable<T> observableSource = upstream.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
            if (transformer != null) {
                observableSource = observableSource.compose(transformer);
            }
            return observableSource;
        };
    }
}
